#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
const int N=1005;

int dp[N][N],n,a[N][N];

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=i;j++) scanf("%d",&a[i][j]);
	dp[1][1]=a[1][1];
	for (int i=2;i<=n;i++)
	{
		for (int j=1;j<i;j++)
		dp[i][j]=max(dp[i-1][j],dp[i-1][j-1])+a[i][j];
		dp[i][i]=dp[i-1][i-1]+a[i][i];
	}
	int ans=0;
	for (int i=1;i<=n;i++) ans=max(ans,dp[n][i]);
	printf("%d\n",ans);
	return 0;
}
